using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Common.Data.DBUpdater;
using Emlyn.Common.Data.SqlServer.SqlManagers;

namespace Emlyn.Website.EmlynORegan.DBUpdateRules
{
    class DUR_0090_ExpandUser: IDBUpdaterRule
    {
        #region IDBUpdaterRule Members

        public int UpgradeFromVersion()
        {
            return 80;
        }

        public int UpgradeToVersion()
        {
            return 90;
        }

        public void PerformUpgrade()
        {
            string ltblEOUserNameConstraint =
                "ALTER TABLE dbo.tblEOUser ADD CONSTRAINT " +
                "IX_tblEOUser UNIQUE NONCLUSTERED " +
                "( " +
                "   UserName " +
                ") ";
            SqlManager.Execute(ltblEOUserNameConstraint);

            string laddFields =
                "ALTER TABLE dbo.tblEOUser ADD " +
                "AuthLevel int NOT NULL CONSTRAINT DF_tblEOUser_AuthLevel DEFAULT 0, " +
                "Email varchar(255) NULL, " +
                "ValidationCode char(8) NOT NULL DEFAULT ' '";

            SqlManager.Execute(laddFields);

            string lupdateExistingUsers =
                "update dbo.tblEOUser " +
                "  set " +
                "    AuthLevel=3, " +
                "    Email='emlynoregan@gmail.com' ";

            SqlManager.Execute(lupdateExistingUsers);
        }

        #endregion
    }
}
